package com.liziba.trend.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liziba.trend.pojo.FundSource;
import com.liziba.trend.service.impl.FundSourceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  获取基金代码前端控制器
 * </p>
 *
 * @author liziba
 * @since 2021-02-04
 */
@RestController
@RequestMapping("/fundSource")
@CrossOrigin
public class FundSourceController {

    /**
     * 基金代码服务
     */
    @Autowired
    private FundSourceServiceImpl fundSourceService;

    /**
     * 获取基金代码
     * @return
     */
    @GetMapping("/index")
    public List<Map> get() {
        List<Map> indexList = new ArrayList<>();
        // 获取所有基金代码
        List<FundSource> fundSources = fundSourceService.list(new QueryWrapper<FundSource>().select("fund_code", "fund_name"));
        for (FundSource fundSource : fundSources) {
            Map<String, String> index = new HashMap<>();
            index.put("code", fundSource.getFundCode());
            index.put("name", fundSource.getFundName());
            indexList.add(index);
        }
        return indexList;
    }

}

